package cn.xenosp.server.web.controller;

import cn.xenosp.server.common.Result;
import cn.xenosp.server.common.annotation.LogInfo;
import cn.xenosp.server.module.activiti.entity.ActivitiModel;
import cn.xenosp.server.module.activiti.service.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目名： service-web
 * 包路径： cn.xenosp.server.web.controller
 * 作者：   TongHui
 * 创建时间: 2025-03-12 16:25
 * 描述: TODO
 * 版本: 1.0
 */
@RestController
@RequestMapping("${app.config.api-base-url}/model/")
public class ModelController {

    @Autowired
    private ModelService modelService;

    @LogInfo(operationModuleType = "工作流模型管理",operationName = "新增",operationContent = "新增")
    @PostMapping("/save")
    public Result<?> save(@RequestBody ActivitiModel activitiModel){
        try {
            return Result.OK("成功",modelService.save(activitiModel));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }
    @LogInfo(operationModuleType = "工作流模型管理",operationName = "修改",operationContent = "修改")
    @PostMapping("/update")
    public Result<?> update(@RequestBody ActivitiModel activitiModel){
        try {
            return Result.OK("成功",modelService.update(activitiModel));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }
    @LogInfo(operationModuleType = "工作流模型管理",operationName = "删除",operationContent = "删除")
    @PostMapping("/del")
    public Result<?> modelDel(@RequestBody ActivitiModel activitiModel){
        try {
            return Result.OK("成功",modelService.removeById(activitiModel.getId()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }
   /* @LogInfo(operationModuleType = "工作流模型管理",operationName = "查询",operationContent = "查询")
    @PostMapping("/getPage")
    public Result<?> modelPage(@RequestBody QueryPageBean queryPageBean){
        try {
            return Result.OK("成功",modelService.getByPaged(queryPageBean));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }*/
    @LogInfo(operationModuleType = "工作流模型管理",operationName = "获取详情信息",operationContent = "获取详情信息")
    @PostMapping("/info")
    public Result<?> modelInfoById(@RequestBody ActivitiModel activitiModel){
        try {
            return Result.OK("成功",modelService.getInfoById(activitiModel.getId()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }
    @LogInfo(operationModuleType = "工作流模型管理",operationName = "导出流程模型",operationContent = "导出流程模型")
    @PostMapping("/export")
    public void modelExport(@RequestBody ActivitiModel activitiModel){
        try {
            modelService.export(activitiModel.getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @LogInfo(operationModuleType = "工作流模型管理",operationName = "部署模型",operationContent = "部署模型")
    @PostMapping("/deploy")
    public Result<?> modelDeploy(@RequestBody ActivitiModel activitiModel){
        try {
            return Result.OK("成功",modelService.deployment(activitiModel.getId()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }

}
